// cookie封装
//增改
function setCookie(username, content, time) {
    var odata = new Date();
    odata.setDate(odata.getDate() + time);
    document.cookie = username + "=" + content + ";expires=" + odata;
};
// 查
function getCookie(key) {
    let arr = document.cookie.split("; ");
    for (let i = 0; i < arr.length; i++) {
        let arr1 = arr[i].split("=");
        if (arr1[0] == key) {
            return arr1[1];
        }
    }
};
// 删除
function removeCookie(username) {
    setCookie(username, 1, -7);
}

// 获取没有定义样式
function getStyles(elem, porp) {
    if (window.getComputedStyle) {
        if (porp) {
            return window.getComputedStyle(elem, null)[porp];
        } else {
            return window.getComputedStyle(elem, null);
        }
    } else {
        if (porp) {
            return elem.currentStyle[porp]
        } else {
            return elem.currentStyle;
        }
    }
}

// 随机颜色
function getmathColor() {
    return "rgb(" +
        Math.floor(Math.random() * 256) + "," +
        Math.floor(Math.random() * 256) + "," +
        Math.floor(Math.random() * 256) + ")"
}

//运动
function animate(element, target, fn) {
    clearInterval(element.itemr)
        // 给传件来的元素添加一个计时器
    element.itemr = setInterval(function() {
            var step = (target - box.offsetLeft) / 7;
            step = step > 0 ? Math.ceil(step) : Math.floor(step);
            console.log(step);
            if (box.offsetLeft == target) {
                box.style.left = target + 'px';
                clearInterval(element.itemr);
                if (fn) {
                    fn();
                }
            } else {
                box.style.left = box.offsetLeft + step + 'px';
            }
        },
        30)
}